<?php

namespace app\libs\DianDianPaySDK\action;

use app\libs\DianDianPaySDK\DianDianPayClient;
use app\libs\DianDianPaySDK\SignatureHandler;

class PaymentApi extends DianDianPayClient
{
    /**
     * @param array $body
     * @return mixed|null
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @doc https://api-doc.diandianpay.com/273187335e0
     */
    public function create_payment(array $body)
    {
        $helper = new SignatureHandler($this->private_key);
        $signature = $helper->generate_signature($this->merchant_id,$this->timestamp,$this->timezone,$body);
        $header = [
            "Content-Type"=>"application/json;charset=UTF-8",
            "signature"=>$signature,
            "timestamp"=>$this->timestamp,
            "timezone"=>$this->timezone];
        return $this->setHeader($header)
        ->setPath("/api/v1/payment")
        ->setMethod('POST')
        ->setOption(['json'=>$body])
        ->send();

    }

    /**
     * @param array $body
     * @return mixed|null
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @doc https://api-doc.diandianpay.com/278789560e0
     */
    public function query_result(array $body)
    {
        $helper = new SignatureHandler($this->private_key);
        $signature = $helper->generate_signature($this->merchant_id,$this->timestamp,$this->timezone,$body);
        $header = [
            "Content-Type"=>"application/json;charset=UTF-8",
            "signature"=>$signature,
            "timestamp"=>$this->timestamp,
            "timezone"=>$this->timezone];
        return $this->setHeader($header)
            ->setPath("/api/v1/payment/result")
            ->setMethod('POST')
            ->setOption(['json'=>$body])
            ->send();
    }
}